//
//  LPCInfoManager.m
//  OurJourney
//
//  Created by 李沛池 on 2017/4/7.
//  Copyright © 2017年 Godlike. All rights reserved.
//

#import "LPCInfoManager.h"

@implementation LPCInfoManager

singleton_implementation(LPCInfoManager);

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initData];
    }
    return self;
}

//初始化数据
- (void)initData
{
    //初始化文案
    [self initTexts];
    //初始化图片
    [self initPictures];
}

- (void)initTexts
{
    //初始化文案
    _arrayLoveTexts = [NSMutableArray arrayWithContentsOfFile:PATH_LoveTexts];
    if (!_arrayLoveTexts || _arrayLoveTexts.count == 0) {
        _arrayLoveTexts = [NSMutableArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"LovePlist" ofType:@"plist"]];
    }
}

//初始化图片
- (void)initPictures
{
    _arrayLovePictures = nil;
    _arrayLovePictures = [[NSMutableArray alloc] init];
    NSString *path = [[NSBundle mainBundle] pathForResource:@"LovePictures" ofType:@"bundle"];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSArray* tempArray = [fileManager contentsOfDirectoryAtPath:PATH_LovePictures error:nil];
    for (NSString* fileName in tempArray) {
        BOOL flag = YES;
        NSString* fullPath = [PATH_LovePictures stringByAppendingPathComponent:fileName];
        if ([fileManager fileExistsAtPath:fullPath isDirectory:&flag]) {
            if (!flag) {
                [_arrayLovePictures addObject:fileName];
            }
        }
    }
    NSDirectoryEnumerator *enumerator = [fileManager enumeratorAtPath:path];
    while((path = [enumerator nextObject]) != nil) {
        NSArray *arrayLovePicturesHidePlist = [NSArray arrayWithContentsOfFile:PATH_LovePicturesHidePlist];
        //先去隐藏列表中找此图片是否需要隐藏
        if (![arrayLovePicturesHidePlist containsObject:path]) {
            [_arrayLovePictures addObject:path];
        }
    }
}

@end
